from library_system.cli import CLI as LibraryCLI
from courses_system.cli import CourseCLI
from social_network.cli import SocialCLI

import sys
from pathlib import Path

class MainCLI:
    def __init__(self):
        sys.path.insert(0, str(Path(__file__).parent.parent))
        self.systems = {
            '1': ('Course Management System', CourseCLI),
            '2': ('Library Management System', LibraryCLI),
            '3': ('Social Network System', SocialCLI)
        }

    def show_main_menu(self):
        print('\n=== Main Menu ===')
        for key in self.systems:
            print(f'[{key}] {self.systems[key][0]}')
        print('[0] Exit System\n')

    def run(self):
        while True:
            self.show_main_menu()
            choice = input('Enter system number: ').strip()
            
            if choice == '0':
                print('System exited. Thank you!')
                break
            
            if choice in self.systems:
                system = self.systems[choice][1]()
                system.run()
            else:
                print('Invalid choice, please try again.')

def main():
    cli = MainCLI()
    cli.run()

if __name__ == "__main__":
    main()